home *** CD-ROM | disk | FTP | other *** search
/ Developer CD Series 1996 July: Mac OS SDK / Dev.CD Jul 96 SDK / Dev.CD Jul 96 SDK1.toast / Development Kits (Disc 1) / OpenDoc Development Framework / ODFDev / ODF / OS / FWODMisc / Sources / FWRect.cpp < prev    next >
Encoding:
Text File  |  1996-04-25  |  23.5 KB  |  794 lines  |  [TEXT/MPS ]

  1. //========================================================================================
  2. //
  3. //    File:                FWRect.cpp
  4. //    Release Version:    $ ODF 1 $
  5. //
  6. //    Copyright:            (c) 1993 - 1996 by Apple Computer, Inc., all rights reserved.
  7. //
  8. //========================================================================================
  9.  
  10. #include "FWOS.hpp"
  11.  
  12. #ifndef FWRECT_H
  13. #include "FWRect.h"
  14. #endif
  15.  
  16. // ----- Foundation Includes -----
  17.  
  18. #ifndef FWFXMATH_H
  19. #include "FWFxMath.h"
  20. #endif
  21.  
  22. #ifndef FWSTREAM_H
  23. #include "FWStream.h"
  24. #endif
  25.  
  26. //========================================================================================
  27. //    RunTime Info
  28. //========================================================================================
  29.  
  30. #ifdef FW_BUILD_MAC
  31. #pragma segment fwodmisc_rect
  32. #endif
  33.  
  34. //========================================================================================
  35. //    struct FW_CPlatformRect
  36. //========================================================================================
  37.  
  38. //----------------------------------------------------------------------------------------
  39. //    FW_CPlatformRect::FW_CPlatformRect
  40. //----------------------------------------------------------------------------------------
  41.  
  42. FW_CPlatformRect::FW_CPlatformRect(const FW_SRect& rect)
  43. {
  44.     left    = FW_FixedToInt(rect.left);
  45.     top        = FW_FixedToInt(rect.top);
  46.     right    = FW_FixedToInt(rect.right);
  47.     bottom    = FW_FixedToInt(rect.bottom);
  48. }
  49.  
  50. //----------------------------------------------------------------------------------------
  51. //    FW_CPlatformRect::operator =
  52. //----------------------------------------------------------------------------------------
  53.  
  54. FW_CPlatformRect& FW_CPlatformRect::operator =(const FW_SRect& rect)
  55. {
  56.     left    = FW_FixedToInt(rect.left);
  57.     top        = FW_FixedToInt(rect.top);
  58.     right    = FW_FixedToInt(rect.right);
  59.     bottom    = FW_FixedToInt(rect.bottom);
  60.     
  61.     return *this;
  62. }
  63.  
  64. //----------------------------------------------------------------------------------------
  65. //    FW_CPlatformRect::operator==
  66. //----------------------------------------------------------------------------------------
  67.  
  68. FW_Boolean FW_CPlatformRect::operator==(const FW_CPlatformRect& rect) const
  69. {
  70.     return
  71.         left    ==    rect.left    &&
  72.         top        ==    rect.top    &&
  73.         right    ==    rect.right    &&
  74.         bottom    ==    rect.bottom;
  75. }
  76.  
  77. //----------------------------------------------------------------------------------------
  78. //    FW_CPlatformRect::operator!=
  79. //----------------------------------------------------------------------------------------
  80.  
  81. FW_Boolean FW_CPlatformRect::operator!=(const FW_CPlatformRect& rect) const
  82. {
  83.     return
  84.         left    !=    rect.left    ||
  85.         top        !=    rect.top    ||
  86.         right    !=    rect.right    ||
  87.         bottom    !=    rect.bottom;
  88. }
  89.  
  90. //----------------------------------------------------------------------------------------
  91. //    FW_CPlatformRect::TopRight
  92. //----------------------------------------------------------------------------------------
  93.  
  94. FW_CPlatformPoint FW_CPlatformRect::TopRight() const
  95. {
  96.     FW_CPlatformPoint point(right, top);
  97.     return point;
  98. }
  99.  
  100. //----------------------------------------------------------------------------------------
  101. //    FW_CPlatformRect::BotLeft
  102. //----------------------------------------------------------------------------------------
  103.  
  104. FW_CPlatformPoint FW_CPlatformRect::BotLeft() const
  105. {
  106.     FW_CPlatformPoint point(left, bottom);
  107.     return point;
  108. }
  109.  
  110. //========================================================================================
  111. //    class FW_CRect
  112. //========================================================================================
  113.  
  114. //----------------------------------------------------------------------------------------
  115. //    FW_CRect::FW_CRect
  116. //----------------------------------------------------------------------------------------
  117.  
  118. FW_CRect::FW_CRect()
  119. {
  120.     left = top = right = bottom    = FW_IntToFixed(0);
  121. }
  122.         
  123. //----------------------------------------------------------------------------------------
  124. //    FW_CRect::FW_CRect
  125. //----------------------------------------------------------------------------------------
  126.  
  127. FW_CRect::FW_CRect(FW_Fixed l, FW_Fixed t, FW_Fixed r, FW_Fixed b)
  128. {
  129.     left    =    l;
  130.     top        =    t;
  131.     right    =    r;
  132.     bottom    =    b;
  133. }
  134.  
  135. //----------------------------------------------------------------------------------------
  136. //    FW_CRect::FW_CRect
  137. //----------------------------------------------------------------------------------------
  138.  
  139. FW_CRect::FW_CRect(const FW_SPoint &topLeft, const FW_SPoint &botRight)
  140. {
  141.     left = topLeft.x;        right = botRight.x;
  142.     top = topLeft.y;        bottom = botRight.y;
  143. }
  144.  
  145. //----------------------------------------------------------------------------------------
  146. //    FW_CRect::FW_CRect
  147. //----------------------------------------------------------------------------------------
  148.  
  149. FW_CRect::FW_CRect(const FW_SPoint &startPoint, const FW_SPoint &endPoint, FW_Fixed penSize)
  150. {
  151.     left = startPoint.x;                
  152.     right = endPoint.x;
  153.     top  = startPoint.y;                
  154.     bottom= endPoint.y;
  155.     
  156.     Sort();
  157.     
  158.     right -= penSize;
  159.     bottom -= penSize;
  160. }
  161.  
  162. //----------------------------------------------------------------------------------------
  163. //    FW_CRect::FW_CRect
  164. //----------------------------------------------------------------------------------------
  165.  
  166. FW_CRect::FW_CRect(const FW_SPoint &topLeft, FW_Fixed width, FW_Fixed height )
  167. {
  168.     left = topLeft.x;        right = left + width;
  169.     top  = topLeft.y;        bottom= top + height;
  170. }
  171.  
  172. //----------------------------------------------------------------------------------------
  173. //    FW_CRect::FW_CRect
  174. //----------------------------------------------------------------------------------------
  175.  
  176. FW_CRect::FW_CRect(const ODRect& rect)
  177. {
  178.     left    =    FW_ODFixedToFixed(rect.left);
  179.     top        =    FW_ODFixedToFixed(rect.top);
  180.     right    =    FW_ODFixedToFixed(rect.right);
  181.     bottom    =    FW_ODFixedToFixed(rect.bottom);
  182. }
  183.  
  184. //----------------------------------------------------------------------------------------
  185. //    FW_CRect::FW_CPoint
  186. //----------------------------------------------------------------------------------------
  187.  
  188. FW_CRect::FW_CRect(FW_CReadableStream& stream)
  189. {
  190.     stream
  191.         >> left
  192.         >> top
  193.         >> right
  194.         >> bottom;
  195. }
  196.  
  197. //----------------------------------------------------------------------------------------
  198. //    FW_CRect:: operator=
  199. //----------------------------------------------------------------------------------------
  200.  
  201. FW_CRect& FW_CRect:: operator=(const ODRect& odRect)
  202. {
  203.     left = FW_ODFixedToFixed(odRect.left);    right = FW_ODFixedToFixed(odRect.right);
  204.     top  = FW_ODFixedToFixed(odRect.top);    bottom= FW_ODFixedToFixed(odRect.bottom);
  205.  
  206.     return *this;
  207. }
  208.  
  209. //----------------------------------------------------------------------------------------
  210. //    FW_CRect::FW_CRect
  211. //----------------------------------------------------------------------------------------
  212.  
  213. FW_CRect::FW_CRect(const FW_SPlatformRect& plfmRect)
  214. {
  215.     left     =    FW_IntToFixed(plfmRect.left);
  216.     top      =    FW_IntToFixed(plfmRect.top);
  217.     right    =    FW_IntToFixed(plfmRect.right);
  218.     bottom    =    FW_IntToFixed(plfmRect.bottom);
  219. }
  220.  
  221. //----------------------------------------------------------------------------------------
  222. //    FW_CRect::FW_CRect
  223. //----------------------------------------------------------------------------------------
  224.  
  225. FW_CRect::FW_CRect(const FW_CRect& rect)
  226. {
  227.     left    =    rect.left;
  228.     top        =    rect.top;
  229.     right    =    rect.right;
  230.     bottom    =    rect.bottom;
  231. }
  232.  
  233. //----------------------------------------------------------------------------------------
  234. //    FW_CRect::FW_CRect
  235. //----------------------------------------------------------------------------------------
  236.  
  237. FW_CRect::FW_CRect(const FW_SRect& rect)
  238. {
  239.     left    =    rect.left;
  240.     top        =    rect.top;
  241.     right    =    rect.right;
  242.     bottom    =    rect.bottom;
  243. }
  244.  
  245. //----------------------------------------------------------------------------------------
  246. //    FW_CRect::operator=
  247. //----------------------------------------------------------------------------------------
  248.  
  249. FW_CRect& FW_CRect::operator=(const FW_SPlatformRect& plfmRect)
  250. {
  251.     left = FW_IntToFixed(plfmRect.left);    right = FW_IntToFixed(plfmRect.right);
  252.     top  = FW_IntToFixed(plfmRect.top);        bottom= FW_IntToFixed(plfmRect.bottom);
  253.  
  254.     return *this;
  255. }
  256.  
  257. //----------------------------------------------------------------------------------------
  258. //    FW_CRect:: operator=
  259. //----------------------------------------------------------------------------------------
  260.  
  261. FW_CRect& FW_CRect:: operator=(const FW_CRect& rect)
  262. {
  263.     left = rect.left;        right = rect.right;
  264.     top  = rect.top;        bottom= rect.bottom;
  265.  
  266.     return *this;
  267. }
  268.  
  269. //----------------------------------------------------------------------------------------
  270. //    FW_CRect:: operator=
  271. //----------------------------------------------------------------------------------------
  272.  
  273. FW_CRect& FW_CRect:: operator=(const FW_SRect& rect)
  274. {
  275.     left = rect.left;        right = rect.right;
  276.     top  = rect.top;        bottom= rect.bottom;
  277.  
  278.     return *this;
  279. }
  280.  
  281. //----------------------------------------------------------------------------------------
  282. //    FW_CRect::Set
  283. //----------------------------------------------------------------------------------------
  284.  
  285. void FW_CRect::Set(FW_Fixed l, FW_Fixed t, FW_Fixed r, FW_Fixed b)
  286. {
  287.     left = l;                right = r;
  288.     top  = t;                bottom= b;
  289. }
  290.  
  291. //----------------------------------------------------------------------------------------
  292. //    FW_CRect::Set
  293. //----------------------------------------------------------------------------------------
  294.  
  295. void FW_CRect::Set(const FW_SPoint &topLeft, FW_Fixed width, FW_Fixed height)
  296. {
  297.     left = topLeft.x;                right = left+width;
  298.     top  = topLeft.y;                bottom= top +height;
  299. }
  300.  
  301. //----------------------------------------------------------------------------------------
  302. //    FW_CRect::Set
  303. //----------------------------------------------------------------------------------------
  304.  
  305. void FW_CRect::Set(const FW_SPoint &topLeft, const FW_SPoint &botRight)
  306. {
  307.     left = topLeft.x;                right = botRight.x;
  308.     top  = topLeft.y;                bottom= botRight.y;
  309. }
  310.  
  311. //----------------------------------------------------------------------------------------
  312. //     FW_CRect::SetInt
  313. //----------------------------------------------------------------------------------------
  314.  
  315. void FW_CRect::SetInt(short l, short t, short r, short b)
  316. {
  317.     left = FW_IntToFixed(l);            right = FW_IntToFixed(r);
  318.     top  = FW_IntToFixed(t);            bottom= FW_IntToFixed(b);
  319. }
  320.  
  321. //----------------------------------------------------------------------------------------
  322. //    FW_CRect::Offset
  323. //----------------------------------------------------------------------------------------
  324.  
  325. void FW_CRect::Offset(FW_Fixed x, FW_Fixed y)
  326. {
  327.     left += x;                right += x;
  328.     top  += y;                bottom+= y;
  329. }
  330.  
  331. //----------------------------------------------------------------------------------------
  332. //    FW_CRect::Offset
  333. //----------------------------------------------------------------------------------------
  334.  
  335. void FW_CRect::Offset(const FW_SPoint &pt)
  336. {
  337.     left += pt.x;            right += pt.x;
  338.     top  += pt.y;            bottom+= pt.y;
  339. }
  340.  
  341. //----------------------------------------------------------------------------------------
  342. //    FW_CRect::Place
  343. //----------------------------------------------------------------------------------------
  344.  
  345. void FW_CRect::Place(FW_Fixed x, FW_Fixed y)
  346. {
  347.     right += x - left;
  348.     left = x;
  349.     bottom += y - top;
  350.     top = y;
  351. }
  352.  
  353. //----------------------------------------------------------------------------------------
  354. //    FW_CRect::Place
  355. //----------------------------------------------------------------------------------------
  356.  
  357. void FW_CRect::Place(const FW_SPoint &pt)
  358. {
  359.     right += pt.x - left;
  360.     left = pt.x;
  361.     bottom += pt.y - top;
  362.     top = pt.y;
  363. }
  364.  
  365. //----------------------------------------------------------------------------------------
  366. //    FW_CRect::PlaceInCenter
  367. //----------------------------------------------------------------------------------------
  368.  
  369. void FW_CRect::PlaceInCenter(const FW_SRect& otherRect)
  370. {
  371.     FW_Fixed newTop     = FW_Half(otherRect.bottom + otherRect.top - bottom + top);
  372.     bottom = newTop + bottom - top;
  373.     top = newTop;
  374.  
  375.     FW_Fixed newLeft    = FW_Half(otherRect.right + otherRect.left - right + left);
  376.     right = newLeft + right - left;
  377.     left = newLeft;        
  378. }
  379.  
  380. //----------------------------------------------------------------------------------------
  381. //    FW_CRect::Inset
  382. //----------------------------------------------------------------------------------------
  383.  
  384. void FW_CRect::Inset(FW_Fixed x, FW_Fixed y )
  385. {
  386.     left += x;
  387.     right -= x;
  388.     top += y;
  389.     bottom -= y;
  390. }
  391.  
  392. //----------------------------------------------------------------------------------------
  393. //    FW_CRect::Clear
  394. //----------------------------------------------------------------------------------------
  395.  
  396. void FW_CRect::Clear( )
  397. {
  398.     left = right = top = bottom = FW_IntToFixed(0);
  399. }
  400.  
  401. //----------------------------------------------------------------------------------------
  402. //    operator|= FW_CPoint
  403. //----------------------------------------------------------------------------------------
  404.  
  405. void FW_CRect:: operator|= (const FW_SPoint &pt)
  406. {
  407.     left     = FW_Minimum(left,pt.x);
  408.     right    = FW_Maximum(right,pt.x);
  409.     top      = FW_Minimum(top,pt.y);
  410.     bottom    = FW_Maximum(bottom,pt.y);
  411. }
  412.  
  413. //----------------------------------------------------------------------------------------
  414. //    FW_CRect::AsPlatformRect
  415. //----------------------------------------------------------------------------------------
  416.  
  417. FW_CPlatformRect FW_CRect::AsPlatformRect() const
  418. {
  419.     return FW_CPlatformRect(
  420.         FW_FixedToInt(left),
  421.         FW_FixedToInt(top),
  422.         FW_FixedToInt(right),
  423.         FW_FixedToInt(bottom));
  424. }
  425.  
  426. //----------------------------------------------------------------------------------------
  427. //    FW_CRect::IsEmpty
  428. //----------------------------------------------------------------------------------------
  429.  
  430. FW_Boolean FW_CRect::IsEmpty() const
  431. {
  432.     return right<=left || bottom<=top;
  433. }
  434.  
  435. //----------------------------------------------------------------------------------------
  436. //    FW_CRect::Contains
  437. //----------------------------------------------------------------------------------------
  438.  
  439. FW_Boolean FW_CRect::Contains(const FW_SPoint &pt) const
  440. {
  441.     return left<=pt.x && pt.x<right
  442.         && top <=pt.y && pt.y<bottom;
  443. }
  444.  
  445. //----------------------------------------------------------------------------------------
  446. //    FW_CRect::Contains
  447. //----------------------------------------------------------------------------------------
  448.  
  449. FW_Boolean FW_CRect::Contains( const FW_SRect &r) const
  450. {
  451.     return left<=r.left && r.right<=right
  452.         && top <=r.top  && r.bottom<=bottom;
  453. }
  454.  
  455. //----------------------------------------------------------------------------------------
  456. //    FW_CRect::operator==
  457. //----------------------------------------------------------------------------------------
  458.  
  459. FW_Boolean FW_CRect::operator==(const FW_SRect &r) const
  460. {
  461.     return (left == r.left && top == r.top  && right == r.right  && bottom == r.bottom);
  462. }
  463.  
  464. //----------------------------------------------------------------------------------------
  465. //    FW_CRect::IsIntersecting
  466. //----------------------------------------------------------------------------------------
  467.  
  468. FW_Boolean FW_CRect::IsIntersecting(const FW_SRect &r) const
  469. {
  470.     return FW_Maximum(left,r.left) < FW_Minimum(right,r.right)
  471.         && FW_Maximum(top,r.top) < FW_Minimum(bottom,r.bottom);
  472. }
  473.  
  474. //----------------------------------------------------------------------------------------
  475. //    FW_CRect::Intersection
  476. //----------------------------------------------------------------------------------------
  477.  
  478. void FW_CRect::Intersection(const FW_SRect &r)
  479. {
  480.     left = FW_Maximum(left, r.left);
  481.     top = FW_Maximum(top, r.top);
  482.     right = FW_Minimum(right, r.right);
  483.     bottom = FW_Minimum(bottom, r.bottom);
  484.     
  485.     if (IsEmpty())
  486.         SetInt(0,0,0,0);
  487. }
  488.  
  489. //----------------------------------------------------------------------------------------
  490. //    FW_CRect::Intersection
  491. //----------------------------------------------------------------------------------------
  492.  
  493. void FW_CRect::Intersection(const FW_SRect &r1, const FW_SRect &r2)
  494. {
  495.     left = FW_Maximum(r1.left, r2.left);
  496.     top = FW_Maximum(r1.top, r2.top);
  497.     right = FW_Minimum(r1.right, r2.right);
  498.     bottom = FW_Minimum(r1.bottom, r2.bottom);
  499.     
  500.     if (IsEmpty())
  501.         SetInt(0,0,0,0);
  502. }
  503.  
  504. //----------------------------------------------------------------------------------------
  505. //    FW_CRect::Union
  506. //----------------------------------------------------------------------------------------
  507.  
  508. void FW_CRect::Union(const FW_SRect &rect)
  509. {
  510.     left = FW_Minimum(left, rect.left);
  511.     right= FW_Maximum(right, rect.right);
  512.     top  = FW_Minimum(top, rect.top);
  513.     bottom=FW_Maximum(bottom, rect.bottom);
  514.     
  515.     if (IsEmpty())
  516.         SetInt(0,0,0,0);
  517. }
  518.  
  519. //----------------------------------------------------------------------------------------
  520. //    FW_CRect::Union
  521. //----------------------------------------------------------------------------------------
  522.  
  523. void FW_CRect::Union(const FW_SRect &r1, const FW_SRect &r2)
  524. {
  525.     left = FW_Minimum(r1.left, r2.left);
  526.     right= FW_Maximum(r1.right, r2.right);
  527.     top  = FW_Minimum(r1.top, r2.top);
  528.     bottom=FW_Maximum(r1.bottom, r2.bottom);
  529.     
  530.     if (IsEmpty())
  531.         SetInt(0,0,0,0);
  532. }
  533.  
  534. //----------------------------------------------------------------------------------------
  535. //    FW_CRect::Sort
  536. //----------------------------------------------------------------------------------------
  537.  
  538. void FW_CRect::Sort()
  539. {
  540.     if (left > right)
  541.     {
  542.         FW_Fixed temp = left;
  543.         left = right;
  544.         right = temp;
  545.     }
  546.     if (top > bottom)
  547.     {
  548.         FW_Fixed temp = top;
  549.         top = bottom;
  550.         bottom = temp;
  551.     }
  552. }
  553.  
  554. //----------------------------------------------------------------------------------------
  555. //    FW_CRect::Map
  556. //----------------------------------------------------------------------------------------
  557. //     The result may not be sorted. You might have to call Sort.
  558.  
  559. void FW_CRect::Map(const FW_SRect& srcRect, const FW_SRect& dstRect)
  560. {
  561.     FW_Fixed size = srcRect.right - srcRect.left;
  562.     FW_Fixed delta1 = dstRect.left - srcRect.left;
  563.     FW_Fixed delta2 = dstRect.right - srcRect.right;
  564.     
  565.     if (size != FW_kFixed0)
  566.     {
  567.         FW_Fixed ratio = (right - left) / size;
  568.         delta1 *= ratio;
  569.         delta2 *= ratio;
  570.     }
  571.  
  572.     left    += delta1;
  573.     right    += delta2;
  574.  
  575.  
  576.     size = srcRect.bottom - srcRect.top;
  577.     delta1 = dstRect.top - srcRect.top;
  578.     delta2 = dstRect.bottom - srcRect.bottom;
  579.  
  580.     if (size != FW_kFixed0)
  581.     {
  582.         FW_Fixed ratio = (bottom - top) / size;
  583.         delta1 *= ratio;
  584.         delta2 *= ratio;
  585.     }
  586.  
  587.     top        += delta1;
  588.     bottom    += delta2;
  589. }
  590.  
  591. //----------------------------------------------------------------------------------------
  592. //    FW_CRect::TopRight
  593. //----------------------------------------------------------------------------------------
  594.  
  595. FW_CPoint FW_CRect::TopRight() const
  596. {
  597.     FW_CPoint point(right, top);
  598.     return point;
  599. }
  600.  
  601. //----------------------------------------------------------------------------------------
  602. //    FW_CRect::BotLeft
  603. //----------------------------------------------------------------------------------------
  604.  
  605. FW_CPoint FW_CRect::BotLeft() const
  606. {
  607.     FW_CPoint point(left, bottom);
  608.     return point;
  609. }
  610.  
  611. //----------------------------------------------------------------------------------------
  612. //    FW_Transform
  613. //----------------------------------------------------------------------------------------
  614.  
  615. void FW_Transform(Environment* ev, FW_SRect& rect, ODTransform* transform)
  616. {
  617. #if FW_OPENDOC_VERSION < FW_OPENDOC_DR4
  618.     * (((ODPoint*) &rect) + 0) =
  619. #endif
  620.     transform->TransformPoint(ev, ((ODPoint*) &rect) + 0);
  621.     
  622. #if FW_OPENDOC_VERSION < FW_OPENDOC_DR4
  623.     * (((ODPoint*) &rect) + 1) =
  624. #endif
  625.     transform->TransformPoint(ev, ((ODPoint*) &rect) + 1);
  626. }
  627.  
  628. //----------------------------------------------------------------------------------------
  629. //    FW_InverseTransform
  630. //----------------------------------------------------------------------------------------
  631.  
  632. void FW_InverseTransform(Environment* ev, FW_SRect& rect, ODTransform* transform)
  633. {
  634. #if FW_OPENDOC_VERSION < FW_OPENDOC_DR4
  635.     * (((ODPoint*) &rect) + 0) =
  636. #endif
  637.     transform->InvertPoint(ev, ((ODPoint*) &rect) + 0);
  638.  
  639. #if FW_OPENDOC_VERSION < FW_OPENDOC_DR4
  640.     * (((ODPoint*) &rect) + 1) =
  641. #endif
  642.     transform->InvertPoint(ev, ((ODPoint*) &rect) + 1);
  643. }
  644.  
  645. //----------------------------------------------------------------------------------------
  646. //    FW_TransformCopy
  647. //----------------------------------------------------------------------------------------
  648.  
  649. FW_CRect FW_TransformCopy(Environment* ev, const FW_SRect& rect, ODTransform* transform)
  650. {
  651.     FW_CRect r(rect);
  652.  
  653. #if FW_OPENDOC_VERSION < FW_OPENDOC_DR4
  654.     * (((ODPoint*) &r) + 0) =
  655. #endif
  656.     transform->TransformPoint(ev, ((ODPoint*) &r) + 0);
  657.  
  658. #if FW_OPENDOC_VERSION < FW_OPENDOC_DR4
  659.     * (((ODPoint*) &r) + 1) =
  660. #endif
  661.     transform->TransformPoint(ev, ((ODPoint*) &r) + 1);
  662.     
  663.     return r;
  664. }
  665.  
  666. //----------------------------------------------------------------------------------------
  667. //    FW_InverseTransformCopy
  668. //----------------------------------------------------------------------------------------
  669.  
  670. FW_CRect FW_InverseTransformCopy(Environment* ev, const FW_SRect& rect, ODTransform* transform)
  671. {
  672.     FW_CRect r(rect);
  673.  
  674. #if FW_OPENDOC_VERSION < FW_OPENDOC_DR4
  675.     * (((ODPoint*) &r) + 0) =
  676. #endif
  677.     transform->InvertPoint(ev, ((ODPoint*) &r) + 0);
  678.  
  679. #if FW_OPENDOC_VERSION < FW_OPENDOC_DR4
  680.     * (((ODPoint*) &r) + 1) =
  681. #endif
  682.     transform->InvertPoint(ev, ((ODPoint*) &r) + 1);
  683.     
  684.     return r;
  685. }
  686.  
  687. //----------------------------------------------------------------------------------------
  688. //    FW_CRect::operator[]
  689. //----------------------------------------------------------------------------------------
  690.  
  691. FW_CPoint& FW_CRect::operator[](FW_PointSelector sel)
  692. {
  693.     return (sel == FW_kTopLeft) ? *((FW_CPoint *) &left) : *((FW_CPoint *) &right);
  694. }
  695.  
  696. //----------------------------------------------------------------------------------------
  697. //    FW_CRect::operator[]
  698. //----------------------------------------------------------------------------------------
  699.  
  700. const FW_CPoint& FW_CRect::operator[](FW_PointSelector sel) const
  701. {
  702.     return (sel == FW_kTopLeft) ? *((FW_CPoint *) &left) : *((FW_CPoint *) &right);
  703. }
  704.  
  705. //----------------------------------------------------------------------------------------
  706. //    FW_CRect::Size
  707. //----------------------------------------------------------------------------------------
  708.  
  709. FW_CPoint FW_CRect::Size() const
  710. {
  711.     return FW_CPoint(right - left, bottom - top);
  712. }
  713.  
  714. //----------------------------------------------------------------------------------------
  715. //    FW_CRect::operator+=
  716. //----------------------------------------------------------------------------------------
  717.  
  718. FW_CRect& FW_CRect::operator+=(const FW_SPoint& pt)
  719. {
  720.     left    +=    pt.x;
  721.     top        +=    pt.y;
  722.     right    +=    pt.x;
  723.     bottom    +=    pt.y;
  724.  
  725.     return *this;
  726. }
  727.  
  728. //----------------------------------------------------------------------------------------
  729. //    FW_CRect::operator+
  730. //----------------------------------------------------------------------------------------
  731.  
  732. FW_CRect FW_CRect::operator+(const FW_SPoint& pt) const
  733. {
  734.     return FW_CRect(
  735.         left    +    pt.x,
  736.         top        +    pt.y,
  737.         right    +    pt.x,
  738.         bottom    +    pt.y);
  739. }
  740.  
  741. //----------------------------------------------------------------------------------------
  742. //    FW_CRect::operator-=
  743. //----------------------------------------------------------------------------------------
  744.  
  745. FW_CRect& FW_CRect::operator-=(const FW_SPoint& pt)
  746. {
  747.     left    -=    pt.x;
  748.     top        -=    pt.y;
  749.     right    -=    pt.x;
  750.     bottom    -=    pt.y;
  751.  
  752.     return *this;
  753. }
  754.  
  755. //----------------------------------------------------------------------------------------
  756. //    FW_CRect::operator-
  757. //----------------------------------------------------------------------------------------
  758.  
  759. FW_CRect FW_CRect::operator-(const FW_SPoint& pt) const
  760. {
  761.     return FW_CRect(
  762.         left    -    pt.x,
  763.         top        -    pt.y,
  764.         right    -    pt.x,
  765.         bottom    -    pt.y);
  766. }
  767.  
  768. //----------------------------------------------------------------------------------------
  769. //    operator<<
  770. //----------------------------------------------------------------------------------------
  771.  
  772. FW_CWritableStream& operator<<(FW_CWritableStream& stream, const FW_SRect& rect)
  773. {
  774.     return stream
  775.         << rect.left
  776.         << rect.top
  777.         << rect.right
  778.         << rect.bottom;
  779. }
  780.  
  781. //----------------------------------------------------------------------------------------
  782. //    operator>>
  783. //----------------------------------------------------------------------------------------
  784.  
  785. FW_CReadableStream& operator>>(FW_CReadableStream& stream, FW_SRect& rect)
  786. {
  787.     return stream
  788.         >> rect.left
  789.         >> rect.top
  790.         >> rect.right
  791.         >> rect.bottom;
  792. }
  793.  
  794.